package de.koller.worlders.server;

import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.zip.Deflater;
import java.util.zip.Inflater;

public class ServerStart {

	public static void main( String[] args ) throws Exception {
		//Compressing Example
		
		byte[] in = new byte[ 2000 ];
		System.out.println( in.length + " " + Arrays.toString( in ) + " " + new String( in ) );
		
		Deflater compressor = new Deflater( Deflater.BEST_COMPRESSION );
		
		compressor.setInput( in );
		compressor.finish();
		
		ByteArrayOutputStream bos = new ByteArrayOutputStream( in.length );
		byte[] buf = new byte[1024];
		while( !compressor.finished() ) {
			int count = compressor.deflate( buf );
			bos.write( buf, 0, count );
		}
		
		in = bos.toByteArray();
		System.out.println( in.length + " " + Arrays.toString( in ) + " " + new String( in ) );
		
		
		Inflater decompressor = new Inflater();
		decompressor.setInput( in );
		
		bos = new ByteArrayOutputStream( in.length );
		buf = new byte[1024];
		while( !decompressor.finished() ) {
			int count = decompressor.inflate( buf );
			bos.write( buf, 0, count );
		}
		
		in = bos.toByteArray();
		System.out.println( in.length + " " + Arrays.toString( in ) + " " + new String( in ) );
	}
	
}
